{
  "properties" : { },
  "id" : "copy1724396602887d39819",
  "script" : null,
  "groupId" : "c0cf605f74e34bc6953194a869f4a6cd",
  "name" : "B5查询最近气象站实时天气情况",
  "createTime" : 1732780546872,
  "updateTime" : 1729475693880,
  "lock" : null,
  "createBy" : "admin",
  "updateBy" : "admin",
  "path" : "/stationweathernearest",
  "method" : "GET",
  "parameters" : [ {
    "name" : "time",
    "value" : "2024-08-15T13:00:00",
    "description" : "数据可以按找小时获取  yyyy-MM-ddTHH:00:00   不填写取最终数据",
    "required" : false,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "lon",
    "value" : "",
    "description" : "经度",
    "required" : true,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "lat",
    "value" : "",
    "description" : "纬度",
    "required" : true,
    "dataType" : "String",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "num",
    "value" : "",
    "description" : "按照距离取最近的多条数据  参数为空时仅取一条",
    "required" : false,
    "dataType" : "Integer",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  }, {
    "name" : "maxdislimit",
    "value" : "",
    "description" : "最大距离限制 超过距离数据无法查询 不传不限制数据",
    "required" : false,
    "dataType" : "Integer",
    "type" : null,
    "defaultValue" : null,
    "validateType" : null,
    "error" : null,
    "expression" : null,
    "children" : null
  } ],
  "options" : [ ],
  "requestBody" : "",
  "headers" : [ ],
  "paths" : [ ],
  "responseBody" : "{\n    \"code\": 0,\n    \"message\": \"success\",\n    \"data\": [\n        {\n            \"stationKey\": \"E2310\",\n            \"lat\": 43.0025,\n            \"lon\": 126.0497,\n            \"high\": 339.8,\n            \"city\": \"吉林市\",\n            \"stationName\": \"磐石石咀\",\n            \"cnty\": \"磐石市\",\n            \"timeBase\": \"2024-08-15T13:00:00\",\n            \"pres\": 999999,\n            \"pres_sea\": 999999,\n            \"temp\": 31,\n            \"temp_max\": 32,\n            \"temp_min\": 30.3,\n            \"humi\": 999999,\n            \"humi_min\": 999999,\n            \"prec\": 0,\n            \"win_10_dir\": 999999,\n            \"win_10_vel\": 999999,\n            \"win_inst_dir\": 999999,\n            \"win_inst_vel\": 999999,\n            \"snow\": 999998,\n            \"WEP_Now\": 999998,\n            \"code\": \"220284\\r\",\n            \"distance\": 4051.2017899652087\n        }\n    ],\n    \"timestamp\": 1725004884561,\n    \"executeTime\": 97\n}",
  "description" : null,
  "requestBodyDefinition" : null,
  "responseBodyDefinition" : {
    "name" : "",
    "value" : "",
    "description" : "",
    "required" : false,
    "dataType" : "Object",
    "type" : null,
    "defaultValue" : null,
    "validateType" : "",
    "error" : "",
    "expression" : "",
    "children" : [ {
      "name" : "code",
      "value" : "1",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "message",
      "value" : "success",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "data",
      "value" : "Hello magic-api",
      "description" : "",
      "required" : false,
      "dataType" : "String",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "timestamp",
      "value" : "1723701688631",
      "description" : "",
      "required" : false,
      "dataType" : "Long",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    }, {
      "name" : "executeTime",
      "value" : "174",
      "description" : "",
      "required" : false,
      "dataType" : "Integer",
      "type" : null,
      "defaultValue" : null,
      "validateType" : "",
      "error" : "",
      "expression" : "",
      "children" : [ ]
    } ]
  }
}
================================
/**
 *   按照机构号码查询、
 *  @param   orgid  系统机构
 *  @param   time        时间格式数据可以按找小时获取  yyyy-MM-ddTHH:00:00   不传查最新 传查指定时间  必须传入整点数据
 *  @param   lon  lat 坐标
 * 
 *     
     left join fx_station_norainday nr on  nr.stationkey = t1.stationkey and DATE(t1.timeBase) = nr.date
 */
import com.mingda.weathermagicapi.WeatherDeal
import 'java.lang.System' as System;
var sql = """

    select stationkey, ST_Distance_Sphere(ST_PointFromText(CONCAT('POINT(',#{lon},' ',#{lat},')')), ST_PointFromText(CONCAT('POINT(',lon,' ',lat,')'))) AS distance
    from station_info
    where 1 = 1 
     <if test="maxdislimit != null and maxdislimit != ''\" > 
     and ST_Distance_Sphere(ST_PointFromText(CONCAT('POINT(',#{lon},' ',#{lat},')')), ST_PointFromText(CONCAT('POINT(',lon,' ',lat,')'))) <= #{maxdislimit} * 1000
      </if>
    order by distance 
    LIMIT <if test="num != null and num != ''\" >#{num}</if> 
        <else>1</else>
     ;
"""

 var nereststation = [];
 //var distance ="";
//查询最近的站点
 var result =  db.select (sql);
 if(result.size() > 0){

     for(item in result){
        nereststation.add(item.stationkey);
     }
     System.out.println("------------------"+nereststation);
     // distance =  result.get(0).distance;
 }
 else{
     return null;
 }

// 获得最近气象站点的数据 ,${distance} as distance
var sql2 = """
    select t1.*,ST_Distance_Sphere(ST_PointFromText(CONCAT('POINT(',#{lon},' ',#{lat},')')), ST_PointFromText(CONCAT('POINT(',lon,' ',lat,')'))) AS distance  from stationdata_hour t1  
    join( select stationKey ,max(timeBase) as latest_timestamp 
    from stationdata_hour
    where 1 = 1 
    <if test="time != null and time != ''\" > and DATE_FORMAT(#{time}, '%Y-%m-%d %H:%i:%s') = timeBase </if>
      and stationKey in 
    <foreach collection="nereststation" item="id" open="(" close=")" separator=",">
		'${id}'
    </foreach>
  
    group by stationKey
    )  t2 on t1.stationKey = t2.stationKey and t1.timeBase = t2.latest_timestamp

      order by distance 
"""

return db.select (sql2);

//return WeatherDeal.getFireLevel(result);

 